/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GraphTest.java
 *
 * Created on 2011-03-30, 21:28:21
 */

package cegg;

import cegg.graph.Graph;
import java.awt.Graphics;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.relation.RelationException;

/**
 *
 * @author kumper
 */
public class GraphTest extends javax.swing.JDialog {

    private Graph graph;

    /** Creates new form GraphTest */
    public GraphTest(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initGraph();
        initComponents();
    }

    public GraphTest(java.awt.Frame parent) {
        super(parent);
        initGraph();
        initComponents();
    }

    private void initGraph()
    {
        graph = new Graph();

        graph.createReason(1, 50, 50)
             .createEffect(2, 50, 100)
             .createReason(3, 100, 50)
             .createEffect(4, 150, 50)
             .createReason(5, 100, 100)
             .createEffect(50, 200, 150)
             .createIntermediate(20, 200, 200)
             .createIntermediate(21, 250, 200)
             .createReason(70, 200, 300)
             .createReason(71, 200, 500)
             .createReason(72, 300, 300)
             .createReason(73, 300, 500)
             .createReason(74, 400, 300)
             .createReason(75, 400, 500)
             .createReason(76, 500, 300)
             .createReason(77, 500, 500)
             .createReason(78, 600, 300)
             .createReason(79, 600, 500);

        try {
            graph.connectEqual(1, 2)
                 .connectEqual(3, 4)
//                 .connect(5, 1)
                 .connectNot(2, 3)
                 .connectEqual(4, 5)
                 .connectAnd(5, 50)
                 .connectOr(3, 20)
                 .connectEqual(21, 50)
                 .makeNegativeDependency(70, 71)
                 .makePositiveDependency(72, 73)
                 .makeAtLeastOneRestriction(74, 75)
                 .makeAtMostOneRestriction(76, 77)
                 .makeExactOneRestriction(78, 79);
        } catch (RelationException ex) {
            Logger.getLogger(GraphTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        graph.paint(g);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 618, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 321, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                GraphTest dialog = new GraphTest(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });

                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
